<?php

namespace App\Models\Shop;

use App\User;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
   protected $fillable = ['order_code', 'user_id', 'status', 'express_id', 'express_code', 'express_money', 'pay_type', 'trade_code', 'total_price'
      ,'free_price','pay_price', 'pay_time', 'picking_time', 'shipping_time', 'finish_time'];


   //订单有很多订单商品
   public function order_products()
   {
      return $this->hasMany(OrderProduct::class);
   }

   //订单属于用户
   public function user()
   {
      return $this->belongsTo(User::class, 'user_id', 'id');
   }

   //一个订单只有一个快递
   public function express()
   {
      return $this->hasOne(Express::class, 'id', 'express_id');
   }

   //一个订单只有一个地址
   public function address()
   {
      return $this->hasOne(Address::class, 'id', 'order_id');
   }
}
